package com.hnx.admin.common.security.aop;

import com.hnx.admin.api.security.core.SecurityPropertyAPI;
import com.hnx.admin.common.security.core.SecurityProperties;
import com.hnx.admin.common.security.utils.RequestContextHolderUtil;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Map;

/*
创建人： 倔强的头发
创建时间：2024/7/14
功能描述:

*/
@Aspect
@Component
@RequiredArgsConstructor
public class SucessVerifyAspect implements SecurityPropertyAPI {
    private final SecurityProperties securityProperties;
    private final com.hnx.admin.common.security.core.VerifyError verifyError;
    @Pointcut("execution(* com.hnx.admin.common.security.handler.*.onAuthenticationSuccess(..))")
    public void pointcut() {}
    @Before("pointcut()")
    public void verify(){
        Map<String, Object> login = RequestContextHolderUtil.getContext();
        String username = (String) login.get(securityProperties.getUsername());
        String errCntKey = verifyError.getRetryKey(username);
        verifyError.clearLoginRecordCache(errCntKey);
    }
}
